﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS.Operations
{
    public class Regions : DetailView<region>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<region> EntityList;
        private new region Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        #region Overrides of DetailView<region>

        public override List<region> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.regions.Where(a => !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override List<region> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.regions.Where(a => a.a_ID == id && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override region GetEntity()
        {
            _context = new project5188Entities();
            Entity = new region();
            return Entity;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override void Insert()
        {
            _context.AddToregions(Entity);
            _context.SaveChanges();
            TransactionId = Entity.a_ID;
        }

        #endregion

        public List<region> GetEntityListByParameters(string regionName)
        {
            _context = new project5188Entities();

            EntityList = _context.regions.Where(a => (a.b_RegionName.Contains(regionName)) && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }
    }
}
